package com.ruoyi.oss.config;

import com.ruoyi.oss.config.properties.OssProperties;
import com.ruoyi.oss.ienum.OssType;
import com.ruoyi.oss.service.CloudOssService;
import com.ruoyi.oss.service.impl.DefaultCloudOssService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Optional;

@Configuration
public class OssServiceConfig {

    /**
     * 根据条件构造构建云上传oss服务
     *
     * @return 构建云上传oss服务
     */
    @Bean
    public CloudOssService cloudOssService(OssProperties ossProperties) {
        OssType ossType = ossProperties.getOssType();
        return Optional.ofNullable(ossType)
                .map(OssType::getServices)
                .map(s -> s.apply(ossProperties))
                .orElseGet(DefaultCloudOssService::new);
    }
}
